package com.zhilong.selenium.component;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.springframework.stereotype.Component;

@Component
public class PurchaseBrowserDriver {
    private static WebDriver webDriver;
    static {
        System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
    }
    public static WebDriver buildChromeNewInstance(){
        close();
        webDriver = new ChromeDriver();
        return webDriver;
    }
    public static WebDriver getCurrentChromeDriver(){
        if (webDriver != null) {
            return webDriver;
        } else {
            return webDriver = new ChromeDriver();
        }
    }

    public static void close(){
        if (webDriver != null) {
            webDriver.quit();

        }
    }
}
